package com.neusoft.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.neusoft.pojo.Dept;
import com.neusoft.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//提供 restFul 服务
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;

    @HystrixCommand(fallbackMethod="hystrixGet")
    @GetMapping("/dept/queryById/{id}")
    public Dept get(@PathVariable int id){
        Dept dept =deptService.queryById((long)id);

        if (dept ==null){
            throw  new  RuntimeException("ID=====>"+id+"不存在");
        }
        return  dept;
    }

    public Dept hystrixGet(@PathVariable int id){
      return new Dept(id,id,"不存在","no database");
    }

}
